New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@zcorky/storage

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zcorky/storage

A minimal API wrapper for localStorage

  • 1.4.7
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

storage

NPM version NPM quality Coverage Status Dependencies Build Status Known Vulnerabilities NPM download license issues

A minimal API wrapper for localStorages, inspired by tsironis/lockr and marcuswestin/store.js. It is written fully with Typescript.

  • 🕒 Familiar store API & patterns
  • 🔥 TypeScript

Install

$ npm install @zcorky/storage

Usage

import storage from '@zcorky/storage';

// set sets the value of the given key
// suport maxAge, unit: ms
storage.set('user', { name:'Marcus' }, 30 * 1000)

// get returns the value of the given key
storage.get('user')

// remove removes the value of the given key
storage.remove('user')

// clear clears the storage
storage.clear()

// keys returns the keys of the storage
storage.keys()

// getAll returns the all items of the storage
storage.getAll()

// has checks whether the given key exists
storage.has('user')

Enhancement

// built-in drivers
//  local       - use localStorage
//  session     - use sessionStorage
//  indexeddb   - use IndexedDB
//  service     - use service with http request
storage.setDriver('session')

// custom prefix
storage.setPrefix('my-prefix-')

Advanced Usage

1. Create a new Storage

Default storage is a global storage with singleton pattern. If you want to create a new storage, you can use storage.create() method.

const storage = storage.create(options);

2. Create Custom Driver

import { StorageDriver } from '@zcorky/storage';

// 1. Create a class implements StorageDriver
export class CustomStorage extends StorageDriver {
  ...
}

// 2. Register the driver
storage.setDriver('custom', CustomStorage)

API

Relatived

  • lockr - A minimal API wrapper for localStorages.
  • store

License

MIT © Moeover

Keywords

FAQs

Package last updated on 06 Apr 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc